<?php

/*
 * Niken Larasati
 * larasati.n@students.amikom.ac.id
 */

class pindah_datang extends CI_Controller {

    public function __construct() {
        parent::__construct();
        $this->load->library('tanggal');
    }

    function form_pindahdatang() {
        $this->load->model('umum_m');
        $data['kat_pindah'] = $this->umum_m->ambil_data('kat_pindah');
        $data['propinsi'] = $this->umum_m->ambil_data('propinsi');

        $this->template->load('halaman_v', 'pindah_datang/tambah_pindahdatang_v', $data);
    }

    function tambah() {
        if ($this->input->post('tambah') != NULL) {
            $data['nomor'] = $this->input->post('nomor');
            $data['idpindah_datang'] = $this->input->post('idpindah_datang');
            $data['idkat_pindah'] = $this->input->post('idkat_pindah');
            $data['nik_pemohon'] = $this->input->post('nik_pemohon');
            $data['nama_pemohon'] = $this->input->post('nama_pemohon');
            $data['tgl_datang'] = $this->input->post('tgl_datang');
            $data['no_kk_lama'] = $this->input->post('no_kk_lama');
            $data['nama_kk'] = $this->input->post('nama_kk_lama');
            $data['alamat_asal'] = $this->input->post('alamat_asal');
            $data['rt'] = $this->input->post('rt_asal');
            $data['rw'] = $this->input->post('rw_asal');
            $data['dusun'] = $this->input->post('dusun');
            $data['desa'] = $this->input->post('desa');
            $data['kecamatan'] = $this->input->post('kecamatan');
            $data['kabupaten'] = $this->input->post('kabupaten');
            $data['idpropinsi'] = $this->input->post('idpropinsi');
            $data['kodepos'] = $this->input->post('kodepos');
            $data['telp'] = $this->input->post('telp');
            $data['jumlah_keluargadatang'] = $this->input->post('jumlah_keluargadatang');

            $this->load->model('umum_m');
            $this->umum_m->tambah('pindah_datang', $data);
            redirect('pindah_datang/tampil');
        }
    }

    function ubah($id = NULL) {
        $this->load->model('umum_m');
        $data['kat_pindah'] = $this->umum_m->ambil_data('kat_pindah');
        $data['propinsi'] = $this->umum_m->ambil_data('propinsi');
        if ($id != NULL) {
            $this->load->model('umum_m');
            $data['data_pindahdatang'] = $this->umum_m->ambil_data('pindah_datang', 'nomor = ' . $id)->row();
            $this->template->load('halaman_v', 'pindah_datang/ubah_pindahdatang_v', $data);
        } else {
            redirect('pindah_datang');
        }
    }

    function simpan_ubah() {
        if ($this->input->post() != NULL) {
            $datang['nomor'] = $this->input->post('nomor');
            $datang['idpindah_datang'] = $this->input->post('idpindah_datang');
            $datang['idkat_pindah'] = $this->input->post('idkat_pindah');
            $datang['nik_pemohon'] = $this->input->post('nik_pemohon');
            $datang['nama_pemohon'] = $this->input->post('nama_pemohon');
            $datang['tgl_datang'] = $this->input->post('tgl_datang');
            $datang['no_kk_lama'] = $this->input->post('no_kk_lama');
            $datang['nama_kk'] = $this->input->post('nama_kk_lama');
            $datang['alamat_asal'] = $this->input->post('alamat_asal');
            $datang['rt'] = $this->input->post('rt_asal');
            $datang['rw'] = $this->input->post('rw_asal');
            $datang['dusun'] = $this->input->post('dusun');
            $datang['desa'] = $this->input->post('desa');
            $datang['kecamatan'] = $this->input->post('kecamatan');
            $datang['kabupaten'] = $this->input->post('kabupaten');
            $datang['idpropinsi'] = $this->input->post('idpropinsi');
            $datang['kodepos'] = $this->input->post('kodepos');
            $datang['telp'] = $this->input->post('telp');
            $datang['jumlah_keluargadatang'] = $this->input->post('jumlah_keluargadatang');

            $this->load->model('umum_m');
            if ($this->umum_m->ubah('pindah_datang', $datang, 'nomor', $datang['nomor'])) {
                redirect('pindah_datang/tampil');
            }
        }
    }

    function tampil() {
        $this->load->model('pindah_datang_m');
        $data['pindah_datang'] = $this->pindah_datang_m->ambil_data();
        $this->template->load('halaman_v', 'pindah_datang/tampil_pindahdatang_v', $data);
    }

    function hapus($id = NULL) {
        $this->load->model('umum_m');
        $this->umum_m->hapus_data_tabel('pindah_datang', array('nomor' => $id));
        $this->tampil();
    }

    function cari_nik() {
        $this->load->model('umum_m');
//        $data['pindah_datang'] = $this->umum_m->ambil_data('pindah_datang');
        if ($this->input->post() != null) {
            $this->load->model('pindah_datang_m');
            $data['pindah_datang'] = $this->pindah_datang_m->detail_cari('pindah_datang.nik_pemohon', $this->input->post('nik_pemohon'));
            $data['nik_pindah_datang'] = $this->input->post('nik_pemohon');
//            echo $this->input->post('nik');
            $this->template->load('halaman_v', 'pindah_datang/cari_nikpindahdatang_v', $data);
        } else {
            $this->load->model('pindah_datang_m');
//            $data['pindah_datang'] = $this->pindah_datang_m->detail_cari();
            $data['pindah_datang'] = $this->pindah_datang_m->ambil_data('pindah_datang');
            $this->template->load('halaman_v', 'pindah_datang/cari_nikpindahdatang_v', $data);
        }
    }

    function cari_nokk() {
        $this->load->model('umum_m');
        $data['pindah_datang'] = $this->umum_m->ambil_data('pindah_datang');
        if ($this->input->post() != NULL) {
            $this->load->model('pindah_datang_m');
            $data['pindah_datang'] = $this->pindah_datang_m->detail_cari(array('pindah_datang.no_kk_lama' => $this->input->post('no_kk')));
            $data['kk_pindah_datang'] = $this->umum_m->native_query('select no_kk_lama from pindah_datang where no_kk_lama=' . $this->input->post('no_kk'))->row();
            $this->template->load('halaman_v', 'pindah_datang/cari_kkpindahdatang_v', $data);
        } else {
            $this->load->model('pindah_datang_m');
            $data['pindah_datang'] = $this->pindah_datang_m->detail_cari();
            $this->template->load('halaman_v', 'pindah_datang/cari_kkpindahdatang_v', $data);
        }
    }

}

?>
